<template>
	<view class='demand'>
		<view class="dem_title">
			绑定身份信息
		</view>
		<view class="main_view">
			<u-form>
				<u-form-item label-width="160" label="姓名"><u-input v-model="form.name" /></u-form-item>
				<u-form-item label-width="160" label="身份证号"><u-input v-model="form.idCard" /></u-form-item>	
			</u-form>
		</view>
		<u-button :ripple="true" type="primary" @click="formsubmit()">确认绑定</u-button>
	</view>
</template>

<script>
	export default {
		props: {},
		data() {
			return {
				form:{
					'id':'',
					'name':'',
					'idCard':''
				}
			}
		},
		onLoad() {
			
		},
		onUnload() {
			
		},
		methods:{
			formsubmit(){
				var value=uni.getStorageSync('myinfo')
				this.form.id=value.user.id
				var url2='http://taruinfo.work:8088/regUser/doBind?id='+this.form.id+'&idcard='+this.form.idCard+'&name='+this.form.name
				uni.request({
					url:url2,
					method:'POST',
					success:function(res){
						if(res.data.code == 200){
							uni.showToast({
								title:'绑定成功,重新登陆',
								icon:'success'
							})
							console.log(res.data)
							// 绑定成功，关闭所有页面，重新登陆
							uni.$emit('isFirstBangding',{isFirstBangding:1})
							setTimeout(function(){
								uni.clearStorage()
								uni.setStorage({
									key:'bangding',
									data:res.data.data.getUserById
								})
								uni.reLaunch({
									url:'../theLogin/index'
								})
							},1500)
						}else{
							uni.showToast({
								title:res.data.message,
								icon:'none'
							})
							// 绑定失败，退出
							setTimeout(function(){
								uni.clearStorage()
								uni.reLaunch({
									url:'../index/index'
								})
							},1500)
						}
					}
				})
			}
		}
	}
</script>

<style scoped>
	.demand{
		box-sizing: border-box;
	}
	.main_view{
		margin-left: 20rpx;
		margin-right: 20rpx;
	}
	.dem_title{
		padding: 0 28rpx;
		padding-top: 12rpx;
		padding-bottom: 38rpx;
		border-bottom: 1rpx solid #e6e6e6;
		font-size: 44rpx;
		font-weight: 900;
		color: #333333;
	}
</style>
